import requests

cookies = {
    'SUB': '_2AkMQqZIpf8NxqwFRmfEVxGnrbY9',
    'SUHB': '0033WrSXqPxfM72-Ws9jqgMF55529P9D9WWEwRCg3RDIxjQoMw-yuETZ'
}

response = requests.get('https://weibo.com', cookies=cookies)
print(response.status_code)


def get_user_info(user_id):
    url = f'https://weibo.com/ajax/profile/info?uid={user_id}'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
        'X-Requested-With': 'XMLHttpRequest',
        'cookie': "SINAGLOBAL=7255082935147.741.1741327644639; "
                  "ULV=1741332334702:2:2:2:5313752480327.731.1741332334627:1741327644812; "
                  "SUB=_2AkMQqZIpf8NxqwFRmfEVxGnrbY9-wwnEieKm9WPyJRMxHRl-yT9kqmIEtRB6Oym8xhaUF_jaZnYdyP-hPPfMxFZEdH8d"
                  "; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WWEwRCg3RDIxjQoMw-yuETZ; "
                  "WBPSESS=voLfPs8eGy8pkyBjwwkfambPdN9sUGkBC-pPwTzS3E-YYd_pxRqJ"
                  "-JwIXYD1z_KdwWfkQPv4_6ronlG1RuoI4tTs_AODvzEX6bVD-xSIVkvt2aMrV9Nj1x81ppzZONaF"
    }

    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        data = response.json()
        user_info = {
            'id': data['data']['user']['id'],
            'screen_name': data['data']['user']['screen_name'],
            'gender': data['data']['user']['gender'],
            'location': data['data']['user']['location'],
            'description': data['data']['user']['description'],
            'followers_count': data['data']['user']['followers_count'],
            'friends_count': data['data']['user']['friends_count'],
            'statuses_count': data['data']['user']['statuses_count'],
            'verified': data['data']['user']['verified']
        }
        return user_info
    else:
        print(f"请求失败，状态码：{response.status_code}")
        return None


print(get_user_info(1669879400))


def get_weibo_list(user_id, page=1):
    url = f'https://weibo.com/ajax/statuses/mymblog?uid={user_id}&page={page}'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
        'X-Requested-With': 'XMLHttpRequest',
        'cookie': "SINAGLOBAL=7255082935147.741.1741327644639; "
                  "ULV=1741332334702:2:2:2:5313752480327.731.1741332334627:1741327644812; "
                  "SUB=_2AkMQqZIpf8NxqwFRmfEVxGnrbY9-wwnEieKm9WPyJRMxHRl-yT9kqmIEtRB6Oym8xhaUF_jaZnYdyP-hPPfMxFZEdH8d"
                  "; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WWEwRCg3RDIxjQoMw-yuETZ; "
                  "WBPSESS=voLfPs8eGy8pkyBjwwkfambPdN9sUGkBC-pPwTzS3E-YYd_pxRqJ"
                  "-JwIXYD1z_KdwWfkQPv4_6ronlG1RuoI4tTs_AODvzEX6bVD-xSIVkvt2aMrV9Nj1x81ppzZONaF"
    }

    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        data = response.json()
        weibo_list = []
        for item in data['data']['list']:
            weibo_info = {
                'id': item['id'],
                'created_at': item['created_at'],
                'text': item['text_raw'],
                'reposts_count': item['reposts_count'],
                'comments_count': item['comments_count'],
                'attitudes_count': item['attitudes_count'],
                'pics': [pic['url'] for pic in item.get('pics', [])]
            }
            weibo_list.append(weibo_info)
        return weibo_list
    else:
        print(f"请求失败，状态码：{response.status_code}")
        return []


if __name__ == '__main__':
    user_id = 1669879400
    weibo_list = get_weibo_list(user_id)
    for weibo in weibo_list:
        print(weibo)

